<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            思路：
            ①暴力法，从n开始递减，判断每个数字是否是单调递增的,但是最后会超时
            */
            var monotoneIncreasingDigits = function (n) {
                function checkNum(n) {
                    let max = Infinity
                    while (n > 0) {
                        let c = n % 10
                        if (max < c) {
                            return false
                        }
                        max = c
                        n = parseInt(n / 10)
                    }
                    return true
                }
                for (let i = n; i >= 0; i--) {
                    if (checkNum(i)) {
                        return i
                    }
                }
            }
            console.log(monotoneIncreasingDigits(1234))
        </script>
    </body>
</html>
